﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ifunction.Fiddler.Model;

namespace ifunction.Fiddler.Configurator
{
    /// <summary>
    /// Interaction logic for FillParametersByRaw.xaml
    /// </summary>
    public partial class FillParametersByRawWindow : Window
    {
        /// <summary>
        /// The main window instance
        /// </summary>
        protected MainWindow mainWindowInstance = null;

        /// <summary>
        /// Initializes a new instance of the <see cref="FillParametersByRawWindow"/> class.
        /// </summary>
        /// <param name="mainWindowInstance">The main window instance.</param>
        public FillParametersByRawWindow(MainWindow mainWindowInstance)
        {
            InitializeComponent();
            this.mainWindowInstance = mainWindowInstance;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FillParametersByRawWindow"/> class.
        /// </summary>
        public FillParametersByRawWindow()
            : this(null)
        {
        }

        /// <summary>
        /// Handles the Click event of the btn_Save control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btn_Save_Click(object sender, RoutedEventArgs e)
        {
            if (mainWindowInstance != null)
            {
                RequestPackage package = new RequestPackage
                {
                    MainRequestRaw = this.text_Main_Raw.Text,
                    KeepSessionRequestRaw = this.text_KeepSession_Raw.Text
                };

                mainWindowInstance.LoadPackageOnUI(package, true);
            }

            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the btn_Clear control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btn_Clear_Click(object sender, RoutedEventArgs e)
        {
            this.text_KeepSession_Raw.Text = this.text_Main_Raw.Text = string.Empty;
        }

        /// <summary>
        /// Handles the Click event of the btn_Close control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btn_Close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
